package com.ordprovider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.service.StaffService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Component
@Transactional
@Service(interfaceClass = StaffService.class)
public class StaffServiceImpl implements StaffService {

    @Resource
    private BooksDao booksDao;

    @Override
    public List<Books> getbooks() {
        return booksDao.getbooks();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addbooksea(Books books) {
        int v = booksDao.addbooksea(books);
        if (v == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean updatebooks(Books books) {
        int v = booksDao.updatebooks(books);
        if (v == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean delectbooks(int id) {
        int v = booksDao.delectbooks(id);
        if (v == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Books getbooksel(int id) {
        return booksDao.getbooksel(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean updatestart(String bcode, int sta) {
        int v = booksDao.updatestart(bcode, sta);
        if (v == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean updateframe(String bcode, int frame) {
        int v = booksDao.updateframe(bcode, frame);
        if (v == 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Integer getbookszlcount(String bname, String bcode, Integer start, Integer frame, String publisher, String tss) {
        return booksDao.getselectvount(bname, bcode, start, frame, publisher, tss);
    }

    @Override
    public List<Books> getbookszl(String bname, String bcode, Integer start, Integer frame, String publisher, String tss, PageUtil pu) {
        int pageSize = pu.getPageSize();
        int totalCount = booksDao.getselectvount(bname, bcode, start, frame, publisher, tss);
        pu.setTotalCount(totalCount);

        if (pu.getCurrentPage() < 1) {
            pu.setCurrentPage(1);
        } else if (pu.getCurrentPage() > pu.getTotalPageCount()) {
            pu.setCurrentPage(pu.getTotalPageCount());
        }
        int qi = (pu.getCurrentPage() - 1) * pu.getPageSize();
        return booksDao.getbooksxz(bname, bcode, start, frame, publisher, tss, qi, pageSize);
    }
}
